package torres.view;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.util.HashMap;

import javax.swing.JPanel;

import torres.entity.Entity;
import torres.entity.NPC;
import torres.map.World;

@SuppressWarnings("serial")
public class DialogueMenuView extends JPanel {
	
	int screenWidth, x, width;
	int screenHeight, y, height;
	NPC entity;
	Entity player;
	HashMap<Integer, Dimension> actionMenuTable;
	
	public DialogueMenuView() {
		
		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		screenWidth = screenSize.width;
		screenHeight = screenSize.height;
		
		setIgnoreRepaint(true);
		setPreferredSize(new Dimension(screenWidth/10,screenHeight/4));
		setLocation(x, y);
		setLayout(null);
		setVisible(true);
		setFocusable(true);
		setOpaque(true);
		
		player = World.getInstance().getPlayer();
	}
	
	public void paintComponent(Graphics g) {
		
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D) g;
		
		g.setColor(Color.black);
		drawWindow(g);
		
		//int yOffset = 30;
		//int xOffset = 20;
		
		Font body = new Font("Helvetica",Font.BOLD, 22);
		
		g.setFont(body);
		g.setColor(Color.black);
		drawActions(g2);
	}
	
	public void drawWindow(Graphics g) {
		ImageLoader loader = new ImageLoader("actionMenuTexture.jpg");
		BufferedImage img = loader.getImage();
	//	Direction dir = player.getDirection();
		if(x!=0&&y!=0) g.drawImage(img,x,y,screenWidth/7,screenHeight/8,null);
	}
	
	public void drawActions(Graphics2D g2) {
		g2.drawString(entity.getDialogue(), x,y+screenHeight/16);
	}
	
	public void update(Graphics g) {
		update(g, entity, x, y);
	}
	
	public void update(Graphics g, NPC e, double x, double y) {
		entity = e;
		this.x = (int)x;
		this.y = (int)y;
		paintComponent(g);
	}
	
	public HashMap<Integer,Dimension> getActionMenuTable() {
		return actionMenuTable;
	}
	
	public int getWidth() {
		return width;
	}
	
	public int getHeight() {
		return height;
	}
}
